package com.yhb.channel.impl.BJCJ;

import com.yhb.channel.ChannelFactory;
import com.yhb.channel.dao.BJCJ.BJCJChannelBoundRelationshipMapper;
import com.yhb.channel.impl.BJCJ.http.BJCJClient;
import com.yhb.channel.provider.ChannelBaseService;
import com.yhb.channel.utils.ChannelLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;

@Service
public class BJCJSubChannelFactory {
    /* ------------常量------------ */
    public static final String CHANNEL_NAME = "北京畅捷";
    public static final String CHANNEL_TYPE = ChannelFactory.BJCJ;

    /* ------------配置------------ */
    @Value("${config.url}")
    private String baseUrl;

    /* ------------Base Provider Beans or utils------------ */
    @Autowired
    private ChannelBaseService channelBaseService;

    /* ------------BJCJ Provider Beans or utils------------ */
    @Autowired
    private BJCJAsyncService asyncService;

    @Autowired
    private BJCJClient bjcjClient;

    @Autowired
    private BJCJChannelBoundRelationshipMapper db;

    /** 启动方法 */
    @PostConstruct
    private void init() {
//        this.setSubChannelConfig("LARGE_CHANNEL18");
//        logger = new ChannelLogger(CHANNEL_NAME + '-' + SUB_CHANNEL_CODE, BJCJException.class, channelBaseService.iUtilProvider);
    }

    /**
     * 根据子通道编号生成子通道
     * @param channelCode 子通道编号
     * @return 北京畅捷子通道对象
     */
    public BJCJChannel getSubChannel(String channelCode) {
        ChannelLogger logger = new ChannelLogger(CHANNEL_NAME + '-' + channelCode,
                BJCJException.class, channelBaseService.iUtilProvider);
        return new BJCJChannel(baseUrl, channelCode, channelBaseService, asyncService, bjcjClient, db, logger);
    }
}
